package com.example.hw_cacaowithoutinputpicture;

import org.jivesoftware.smack.XMPPConnection;

import com.example.hw_cacaowithoutinputpicture.XMPPManager.OnLoginListener;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

	public String USERNAME = null;
	public String PASSWORD = null ;
	
	EditText userName;
	EditText password;
	
	private XMPPConnection mXmppConnection;
	
	ListView mList;
	ArrayAdapter<User> mAdapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		userName = (EditText)findViewById(R.id.editText1);
		password = (EditText)findViewById(R.id.editText2);
		
		Button btn = (Button)findViewById(R.id.login);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				USERNAME = userName.getText().toString();
				PASSWORD = password.getText().toString();
				XMPPManager.getInstance().login(USERNAME, PASSWORD, new OnLoginListener() {
					
					@Override
					public void onLoginSuccess(String username) {
						// TODO Auto-generated method stub
						Toast.makeText(MainActivity.this, "login success", Toast.LENGTH_SHORT).show();
						Intent i = new Intent(MainActivity.this, SubActivity.class);
						startActivity(i);
					}
					
					@Override
					public void onLoginFail(String username) {
						// TODO Auto-generated method stub
						Toast.makeText(MainActivity.this, "login failed", Toast.LENGTH_SHORT).show();
					}
				});
				
			}
		});
		
		btn = (Button)findViewById(R.id.cancel);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(MainActivity.this, SubActivity.class);
				startActivity(i);
			}
		});
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
